<?php
include "./conf/.htconfig.php";
include "./conf/conn.php";
if (isset($_POST['relMark'])) {
  $relMark = htmlspecialchars(trim($_POST['relMark']));
} else {
  exit("{\"result\" : 0, \"error\" : \"Relative mark not set.\"}");
}

if (isset($_POST['timeMark'])) {
  $timeMark = htmlspecialchars(trim($_POST['timeMark']));
} else {
  exit("{\"result\" : 0, \"error\" : \"Time mark not set.\"}");
}

if (isset($_POST['color'])) {
  $color = htmlspecialchars(trim($_POST['color']));
} else {
  exit("{\"result\" : 0, \"error\" : \"Color not set.\"}");
}

if (isset($_POST['video'])) {
  $video = htmlspecialchars(trim($_POST['video']));
} else {
  exit("{\"result\" : 0, \"error\" : \"Video not set.\"}");
}

if (isset($_POST['id'])) {
  $id = htmlspecialchars(trim($_POST['id']));
} else {
  exit("{\"result\" : 0, \"error\" : \"ID not set.\"}");
}

$query = "INSERT INTO " . $conf['db_video_table'] . " (video, sname, mark, time, color) VALUES ('$video', '$id', '$relMark', '$timeMark', '$color')";
$result = mysql_query($query);

if ($result) {
  if (isset($_POST['text'])) {
    $text = htmlspecialchars(trim($_POST['text']));
    $mark_id = mysql_insert_id();
    $query = "INSERT INTO " . $conf['db_textmark_table'] . " (id, text) VALUES (" . $mark_id . ", '" . $text . "')";
    $result = mysql_query($query);
  }
}
if ($result) {
  echo "{\"result\" : 1, \"error\" : \"\"}";
} else {
  echo "{\"result\" : 0, \"error\" : \"" . mysql_error() . "\"}";
}
mysql_close($con);
?>